<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>执照管理</el-breadcrumb-item>
      <el-breadcrumb-item>执照报名</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-table :data="examData" style="width: 100%">
        <el-table-column prop="examName" label="考试名称" width="180"></el-table-column>
        <el-table-column prop="examStartTime" label="开始日期" width="180"></el-table-column>
        <el-table-column prop="examEndTime" label="结束日期" width="180"></el-table-column>
        <el-table-column prop="examCode" label="考试类别"></el-table-column>
        <el-table-column prop="examLevel" label="考试等级"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button  @click="openjoinExam(scope.row)">报名</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <el-dialog title="报名" :visible.sync="joinExamDialogVisible" width="50%">
     
       <span>确定要报名么？</span>

        <el-button @click="joinExamDialogVisible=false">取 消</el-button>
        <el-button type="primary" @click="joinExam()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<style lang="less" scoped>
</style>
<script>
export default {
  data() {
    return {
      examData: [],
      joinExamDialogVisible: false,
      willJoinExam:'',

    };
  },
  created() {
    this.getExamList();
  },
  methods: {
    //获取考试列表
    async getExamList() {
      const { data: res } = await this.$http.get("asfc-exam/getAllExam");

      if (res.code !== 200) {
        this.$message.error("获取失败！");
      }
      this.examData = res.data;
    },
    //打开报名表
    async openjoinExam(exam){
    
    // 首先年龄判断
 const { data: res } = await this.$http.get(`join-exam-user/sureAge?id=${exam.examId}`);
 if (res.code !== 200) {
       return this.$message.error(res.msg);
      }
  this.willJoinExam=exam.examId
    this.joinExamDialogVisible=true

    },
    async joinExam(){

const { data: res } = await this.$http.put(`join-exam-user/addJoinExamUser?id=${this.willJoinExam}`);
if (res.code !== 200) {
       return this.$message.error("报名失败");
      }
      this.$message.success(res.msg);
 this.joinExamDialogVisible=false
    }
  },
};
</script>